package notebook.client;

import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONString;
import com.google.gwt.json.client.JSONValue;

public class FieldVerifier {

	private static JSONValue getNoNull(JSONValue s){
		if(s==null)return new JSONString("");
		else return s;
	}
	public static String hasTitle(JSONObject pv) {
		if (getNoNull(pv.get("title")).isString().stringValue().length()<1) {
			return "还没有输入标题";
		}
		return "";
	}
	public static String hasContent(JSONObject saying) {
		if (getNoNull(saying.get("content")).isString().stringValue().length()<10) {
			return "还没有输入内容或内容太短";
		}
		return "";
	}
	public static String isValidUrl(JSONObject ws) {
		if (getNoNull(ws.get("url")).isString().stringValue().length()<10) {
			return "还没有输入网址或网址太短";
		}
		if (getNoNull(ws.get("url")).isString().stringValue().length()>100) {
			return "网址太长";
		}
		return "";
	}
	public static String isValidArticle(JSONObject dto){
		StringBuffer sb = new StringBuffer(hasContent(dto));
		sb.append(hasTitle(dto));
		return sb.toString();
	}
	public static String isValidSaying(JSONObject dto){
		StringBuffer sb = new StringBuffer(hasContent(dto));
		return sb.toString();
	}
}
